package com.muyu.danmo.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.danmo.domain.DanmoMountFavorite;
import com.muyu.danmo.domain.DanmoPrintingMessage;
import com.muyu.danmo.mapper.DanmoMountMessageMapper;
import com.muyu.danmo.service.IDanmoMountFavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 装裱收藏Controller
 * 
 * @author kunzong
 * @date 2024-12-05
 */
@RestController
@RequestMapping("/DanmoMountFavorite")
public class DanmoMountFavoriteController extends BaseController
{
    @Autowired
    private IDanmoMountFavoriteService danmoMountFavoriteService;

    /**
     * 查询装裱收藏列表
     */
//    @RequiresPermissions("system:DanmoMountFavorite:list")
    @GetMapping("/list")
    public Result list(DanmoMountFavorite danmoMountFavorite)
    {
        PageHelper.startPage(danmoMountFavorite.getPageNum(), danmoMountFavorite.getPageSize());
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser == null || loginUser.getUserid() == null) {
            return Result.notLoggedIn("请登录");
        }
        Long userId = loginUser.getUserid();
        List<DanmoMountFavorite> list = danmoMountFavoriteService.selectDanmoMountFavoriteList(userId);
        PageInfo<DanmoMountFavorite> danmoInformationPageInfo = new PageInfo<>(list);
        return Result.success(danmoInformationPageInfo);
    }

    /**
     * 导出装裱收藏列表
     */
/*    @RequiresPermissions("system:DanmoMountFavorite:export")
    @Log(title = "装裱收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoMountFavorite danmoMountFavorite)
    {
        List<DanmoMountFavorite> list = danmoMountFavoriteService.selectDanmoMountFavoriteList(danmoMountFavorite);
        ExcelUtil<DanmoMountFavorite> util = new ExcelUtil<DanmoMountFavorite>(DanmoMountFavorite.class);
        util.exportExcel(response, list, "装裱收藏数据");
    }*/

    /**
     * 获取装裱收藏详细信息
     */
//    @RequiresPermissions("system:DanmoMountFavorite:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return Result.success(danmoMountFavoriteService.selectDanmoMountFavoriteById(id));
    }

    /**
     * 新增装裱收藏
     */
//    @RequiresPermissions("system:DanmoMountFavorite:add")
    @Log(title = "装裱收藏", businessType = BusinessType.INSERT)
    @GetMapping("/add/{id}")
    public Result add(@PathVariable("id") Long id)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser == null || loginUser.getUserid() == null) {
            return Result.notLoggedIn("请登录");
        }
        Long userId = loginUser.getUserid();
        return danmoMountFavoriteService.insertDanmoMountFavorite(id, userId);
    }

    /**
     * 修改装裱收藏
     */
//    @RequiresPermissions("system:DanmoMountFavorite:edit")
    @Log(title = "装裱收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoMountFavorite danmoMountFavorite)
    {
        return Result.success(danmoMountFavoriteService.updateDanmoMountFavorite(danmoMountFavorite));
    }

    /**
     * 取消装裱收藏
     */
//    @RequiresPermissions("system:DanmoMountFavorite:remove")
    @Log(title = "装裱收藏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser == null || loginUser.getUserid() == null) {
            return Result.notLoggedIn("请登录");
        }
        Long userId = loginUser.getUserid();
        return danmoMountFavoriteService.deleteDanmoMountFavoriteByIds(userId, ids);
    }
}
